package classpath

import (
	"hi-jvm/util"
	"os"
	"strings"
)

const PathListSeparator = string(os.PathListSeparator)

type Entry interface {
	ReadClass(className string) ([]byte, Entry, error)
	String() string
}

func NewEntry(path string) Entry {
	if len(path) < 1 {
		return nil
	}

	if strings.Contains(path, PathListSeparator) {
		return NewCompositeEntry(path)
	}

	if strings.HasSuffix(path, "*") {
		return NewWidcardEntry(path)
	}

	if util.HasSuffixOr(path, []string{".jar", ".JAR", ".zip", ".ZIP"}) {
		return NewZipEntry(path);
	}
	return NewDirEntry(path)
}
